package org.bwapi.bridge.model;

import java.util.Set;

import org.apache.commons.collections15.Transformer;
import org.bwapi.bridge.swig.BaseLocationSet;
import org.bwapi.bridge.swig.BaseLocationSetIterator;
import org.bwapi.bridge.swig.BaseLocationSpacelessSet;
import org.bwapi.bridge.swig.BaseLocationSpacelessSetIterator;
import org.bwapi.bridge.swig.SWIGTYPE_p_BaseLocation;
import org.bwapi.bridge.swig.SWIGTYPE_p_std__setT_BWTA__BaseLocation_p_t;
import org.bwapi.bridge.swig.SWIGTYPE_p_std__setT_BaseLocation_p_t;
import org.cretz.swig.collection.NativeSet;
import org.cretz.swig.util.SwigUtils;

/**
 * Base location
 * 
 * @see <a href="http://code.google.com/p/bwta/wiki/BaseLocation">BaseLocation</a>
 * 
 * @author Chad Retz
 * 
 * @since 0.2
 */
public class BaseLocation {
	private static final Transformer<BaseLocation, org.bwapi.bridge.swig.BaseLocation> FROM = 
		new Transformer<BaseLocation, org.bwapi.bridge.swig.BaseLocation>() {
			@Override
			public org.bwapi.bridge.swig.BaseLocation transform(BaseLocation location) {
				return location.getLocation();
			}
		};
		
	private static final Transformer<org.bwapi.bridge.swig.BaseLocation, BaseLocation> TO = 
		new Transformer<org.bwapi.bridge.swig.BaseLocation, BaseLocation>() {
			@Override
			public BaseLocation transform(org.bwapi.bridge.swig.BaseLocation location) {
				return new BaseLocation(location);
			}
		};
		
	private static final Transformer<BaseLocation, SWIGTYPE_p_BaseLocation> FROM_SPACELESS = 
		new Transformer<BaseLocation, SWIGTYPE_p_BaseLocation>() {
			@Override
			public SWIGTYPE_p_BaseLocation transform(BaseLocation location) {
				return location.getPointer();
			}
		};
		
	private static final Transformer<SWIGTYPE_p_BaseLocation, BaseLocation> TO_SPACELESS = 
		new Transformer<SWIGTYPE_p_BaseLocation, BaseLocation>() {
			@Override
			public BaseLocation transform(SWIGTYPE_p_BaseLocation location) {
				return new BaseLocation(location);
			}
		};
		
	static Set<BaseLocation> newSet(SWIGTYPE_p_std__setT_BWTA__BaseLocation_p_t nativeSet) {
		return new NativeSet<BaseLocation, org.bwapi.bridge.swig.BaseLocation>(
				org.bwapi.bridge.swig.BaseLocation.class, BaseLocationSetIterator.class, 
				nativeSet, BaseLocationSet.class, FROM, TO);
	}
	
	static Set<BaseLocation> newSet(SWIGTYPE_p_std__setT_BaseLocation_p_t nativeSet) {
		return new NativeSet<BaseLocation, SWIGTYPE_p_BaseLocation>(
				SWIGTYPE_p_BaseLocation.class, BaseLocationSpacelessSetIterator.class, 
				nativeSet, BaseLocationSpacelessSet.class, FROM_SPACELESS, TO_SPACELESS);
	}

	private final org.bwapi.bridge.swig.BaseLocation location;

	BaseLocation(org.bwapi.bridge.swig.BaseLocation location) {
		this.location = location;
	}
	
	BaseLocation(SWIGTYPE_p_BaseLocation location) {
		this(SwigUtils.getSwigPointer(SwigUtils.getSwigPointer(location), 
				false, org.bwapi.bridge.swig.BaseLocation.class));
	}
	
	org.bwapi.bridge.swig.BaseLocation getLocation() {
		return location;
	}
	
	SWIGTYPE_p_BaseLocation getPointer() {
		return SwigUtils.getSwigPointer(location, SWIGTYPE_p_BaseLocation.class);
	}

	public Position getPosition() {
		return new Position(location.getPosition());
	}

	public TilePosition getTilePosition() {
		return new TilePosition(location.getTilePosition());
	}

	public Region getRegion() {
		org.bwapi.bridge.swig.Region region = location.getRegion();
		return region == null ? null : new Region(region);
	}

	public int minerals() {
		return location.minerals();
	}

	public int gas() {
		return location.gas();
	}

	public Set<Unit> getMinerals() {
		return Unit.newSet(location.getMinerals());
	}

	public Set<Unit> getStaticMinerals() {
		return Unit.newSet(location.getStaticMinerals());
	}

	public Set<Unit> getGeysers() {
		return Unit.newSet(location.getGeysers());
	}

	public double getGroundDistance(BaseLocation other) {
		return location.getGroundDistance(other.getLocation());
	}

	public double getAirDistance(BaseLocation other) {
		return location.getAirDistance(other.getLocation());
	}

	public boolean isIsland() {
		return location.isIsland();
	}

	public boolean isMineralOnly() {
		return location.isMineralOnly();
	}

	public boolean isStartLocation() {
		return location.isStartLocation();
	}
}
